package com.ants.boot.wx.controller;

import com.ants.boot.core.Response;
import com.ants.boot.wx.dto.wxcheckin.LastOrNextMonthDto;
import com.ants.boot.wx.service.WxCheckinService;
import com.ants.boot.wx.vo.wxcheckin.WxCheckinVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 蚂蚁会花呗
 * @date 2022/5/31 10:07
 */
@RestController
@RequestMapping("wx/checkin")
@Api(tags = "签到功能")
public class WxCheckinController{

    @Autowired
    private WxCheckinService wxCheckinService;

    /**
     * 当前月
     * @return
     */
    @GetMapping("get_current_month")
    @ApiOperation(value="当前月签到",notes="获取当前月签到日期")
    @ApiResponses({
            @ApiResponse(code = 200,message = "操作成功！",response = WxCheckinVo.class)
    })
    public Response getCurrentMonth(){
        return Response.okData(wxCheckinService.getCurrentMonth());
    }


    /**
     * 上一月或者下一月
     * @param dto
     * @return
     */
    @PostMapping("last_or_next_month")
    @ApiOperation(value="上个月或者下个月签到",notes="获取上个月或者下个月签到日期数组")
    @ApiResponses({
            @ApiResponse(code = 200,message = "操作成功！",response = WxCheckinVo.class)
    })
    public Response lastOrNextMonth(@RequestBody @Validated LastOrNextMonthDto dto){
        return Response.okData(wxCheckinService.lastOrNextMonth(dto));
    }

    /**
     * 签到
     * @return
     */
    @PostMapping("add_date")
    @ApiOperation(value="签到",notes="当前日期签到")
    public Response addDate(){
        boolean result = wxCheckinService.addDate();
        if (!result){
            return Response.fail();
        }
        return Response.ok();
    }


}
